/**
 * Created by huzhihui on 2016/10/17.
 */
$(function(){
//	isRedirectMainView();
	/**
	 * form-登录
	 */
	$('#login_submit').click(function(e){
		// location.href = "admin.html";
		if($("#userName").val().length ==0 ||
			$('#password').val().length == 0){
			layer.alert('请输入完整信息');
		}else{
			var loginParam = {
				'username' : $("#userName").val(),
				'password' : $.md5($('#password').val())
			};
			$.ajax({
				type:"post",
				url:$api.login.login,
				dataType:'json',
				contentType : 'application/json',
				data:JSON.stringify(loginParam),
				beforeSend : function () {
					//layerLoad = layer.load();
				},
				success:function(data){
					 if(!$checkRemouteStatus(data)){
						 	layer.close(layerLoad);
						 	return;
						 }
					if(data.code==000000){
						location.href = "admin.html";
					}else{
						layer.alert(data.message);
					}
				}
			});
		}
	});
});

/**
 * 若用户已经登录则
 * 在页面刷新的时候直接进入登录后主页
 */
function isRedirectMainView(){
	$.ajax({
		 type:"post",
		 url:$api.login.checkUserIsLogin,
		 dataType:'json',
		 success:function(data){
			 if(data.code == "000000"){
				 location.href = "admin.html";
			 }else{
				 return false;
			 }
		 }
	});
}
/*回车登陆*/
$(document).keyup(function(event){
  if(event.keyCode ==13){
    $("#login_submit").trigger("click");
  }
});